package com.xiake.consultsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiake.consultsystem.pojo.po.Counselor;
import com.xiake.consultsystem.mapper.CounselorMapper;
import com.xiake.consultsystem.service.CounselorService;
import com.xiake.consultsystem.pojo.vo.AvailableAppointListVo;
import com.xiake.consultsystem.pojo.vo.CounselorVo;
import com.xiake.consultsystem.pojo.vo.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr.Chen
 * @since 2022-11-13
 */
@Service
public class CounselorServiceImpl  implements CounselorService {

    @Autowired
    CounselorMapper counselorMapper;
    /**
     * 根据id获取咨询师所有信息
     *
     * @param id 咨询师Id
     * @return
     */
    @Override
    public Result getNameById(Long id) {
        Counselor counselor = counselorMapper.selectById(id);
        return Result.success(counselor.getCounselorName());
    }

    /**
     * 获取咨询师列表
     * @return
     */
    @Override
    public Result getAllName() {
        LambdaQueryWrapper<Counselor> queryWrapper = new LambdaQueryWrapper<>();
        List<Counselor> counselorList = counselorMapper.selectList(queryWrapper);
        List<CounselorVo> counselorVoList = copyList(counselorList);
        return Result.success(counselorVoList);
    }

    /**
     * 根据日期获取对应的时间段、咨询师、预约状态
     * @param date
     * @return
     */
    @Override
    public Result showAvailableCounselor1(Date date) {
        List<AvailableAppointListVo> availableAppointListVos = counselorMapper.showAvailableCounselor1(date);
        return Result.success(availableAppointListVos);
    }

    /**
     * 根据日期和咨询师id获取对应的时间段、咨询师、预约状态
     * @param date
     * @return
     */
    @Override
    public Result showAvailableCounselor2(Date date,Long counselorId) {
        List<AvailableAppointListVo> availableAppointListVos  = counselorMapper.showAvailableCounselor2(date,counselorId);
        return Result.success(availableAppointListVos);
    }

    /**
     * 批量转换VO对象
     * @param counselorList
     * @return
     */
    private List<CounselorVo> copyList(List<Counselor> counselorList) {
        List<CounselorVo> counselorVoList = new ArrayList<>();
        for (Counselor recod:counselorList) {
            counselorVoList.add( copy(recod));
        }
        return counselorVoList;
    }
    //转化单个
    private CounselorVo copy(Counselor recod) {
        CounselorVo counselorVo = new CounselorVo();
        BeanUtils.copyProperties(recod,counselorVo);
        return counselorVo;
    }

}
